package com.sample.thread.countDownLatch;

import java.util.concurrent.CountDownLatch;

/**
* @comments
* @author  zg
* @date 2021年3月12日
*/
public class CountDownLatchTester {

	public static void main(String[] args) throws InterruptedException {
		//构造函数传的数字必须与线程数一致，这里使用5个线程
		CountDownLatch counter = new CountDownLatch(5);
		
		CountThread t1 = new CountThread(counter, "线程【一】", 10);
		CountThread t2 = new CountThread(counter, "线程【二】", 5);
		CountThread t3 = new CountThread(counter, "线程【三】", 7);
		CountThread t4 = new CountThread(counter, "线程【四】", 13);
		CountThread t5 = new CountThread(counter, "线程【五】", 3);
		
		t1.start();
		t2.start();
		t3.start();
		t4.start();
		t5.start();
		
		counter.await();//等待所有线程执行完毕
		
		System.out.println("全部线程计数完毕！");
	}
	
}
